<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="presentation.PresentationsBean"%>

<%@page import="db.Album"%><html xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="presentation.Get16ImagesBean"%>   
<%@page import="presentation.Get16AlbumsBean"%> 
<%@page import="presentation.GetAllAlbumsBean"%>
<head>
	<link rel="stylesheet" type="text/css" href="css/styleGallery.css" />  
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Пациенти</title>
</head>

<body id="bd">

<div id="container">
	<my:header/>
	
	 <%   Integer pageNum =null;
	    try{
	 		 pageNum = Integer.parseInt(request.getParameter("page"));
		}catch( Exception e){  			
			pageNum=1;
		};   
	    GetAllAlbumsBean b = new GetAllAlbumsBean(pageNum);
	    
     	
     	List<Album> userAlbums =b.getAlbums();
       	long allALlNum=b.getAllAlbumsNum();
       	Long userid=0L;
   	  %>
   	  <%if (session.getAttribute("user")==null){ %>
		<my:menulogout/>
		<%}else{ %>
		<%	userid=(Long)session.getAttribute("userid");
       	    List<Album> allUserAlbums =b.getUserAlbums(userid);%>
		<my:menulogin/>
<%} %> 	

   		<%
   		if (userAlbums.isEmpty()) {
   		%>
   		<div id="midcontainer">
   			<p id="err">Няма създадени пациенти до момента!</p>
   		<%}else{
   		%>
   		<div id="midcontainer">
   		  <table>
   		<% 	
   		 	 for ( int i=0; i<userAlbums.size();i++){%>
 
   		 	<%if(i%4==0){%>
   		   <tr></tr>
   		 <%};%>
          		<td> <div id ="pic">
            	 	 <li style=" display:inline;float:left;"><a href="ViewAlbum.jsp?album_id=<%=userAlbums.get(i).getAlbumId() %>"><img style="img-decoration:none; border-style:none;"src="img/folder_images.png"/></a></li>
            	 	 <li> <%=userAlbums.get(i).getAlbumName() %> </li>
             	 	<br>
             	 	<%if (session.getAttribute("user")!=null){ %>
             	 		<%if (b.isUserAlbum(userid,userAlbums.get(i).getAlbumId())){%>
            	 	 <li style="text-decoration:none;margin:0px 0px; padding:0px; display : inline;">
         		      <a href="EditAlbumServlet?album_id=<%=userAlbums.get(i).getAlbumId() %>" title="edit"><img style="img-decoration:none; border-style:none;" src="img/editFolder.png"/></a></li>
             	 	<li style="text-decoration:none;margin:0px 0px; padding:0px; display : inline;">
         	 	     <a href="DeleteAlbumServlet?album_id=<%=userAlbums.get(i).getAlbumId() %>" title="delete"><img style="img-decoration:none; border-style:none;" src="img/delFolder.png"/></a></li>
           		<%}} %>
           		</div>
           		 </td>        
   		   <%};%>
  </table> 		   
  			 <div id="page">
         <%
           if ((pageNum==1)&&(allALlNum>1)){ %>
              <li> Prev &nbsp;</li>		
   		      <li> <a class="number" href="Albums.jsp?page=<%=++pageNum%>">&nbsp; Next<a></li>
          <%}else if(( pageNum==allALlNum )&&(allALlNum!=1)){
        	 %>
             <li> <a class="number" href="Albums.jsp?page=<%=--pageNum%>">&nbsp; Prev<a></li>	
   		    <li>&nbsp; Next</li>
         <%}else if(( pageNum==allALlNum )&&(allALlNum==1)){
        	 %>
             <li>&nbsp; Prev</li>	
   		    <li>&nbsp; Next</li>
   		    <%}else{ %>
  	        <li> <a class="number" href="Albums.jsp?page=<%=--pageNum%>">&nbsp; Prev<a></li>	
  	        <%pageNum++;%>	
   		<li> <a class="number" href="Albums.jsp?page=<%=++pageNum%>">&nbsp; Next<a></li>
   		<%} %>
    </div>
   		<%} %>	
   		
	
</div><!-- midcontainer -->
<%b.releaseResources(); %>
<my:footer/>
</body>
</html>